﻿<?php
$title="Modify Password";
$css="productAdd.css";
include_once 'common/AdminTop.php';
include_once 'authentic.php';
include_once '../Class/DB.php';
$db=new DB();
$old=$_POST["password0"];
$new1=$_POST["password1"];
$new2=$_POST["password2"];

if(isset($_POST["password0"])){//press submit
if($old==""||$new1==""||$new2=="")
{
	
}
else
{
	if($old!=$_SESSION["Admin"]["password"])
	{
		?>
	<script language="JavaScript">
	alert("Wrong old password!");
	window.location.href="modifyPwd.php";
	</script>	
	<?php
	exit();
	}
	else if($new1!=$new2){
		?>
	<script language="JavaScript">
	alert("Please confirm your password!");
	window.location.href="modifyPwd.php";
	</script>	
	<?php
	}
	else{
		$db->update_admin_pwd($new1);
		$_SESSION["Admin"]["password"]=$new1;
		?>
	<script language="JavaScript">
	window.location.href="index.php";
	</script>	
	<?php
	}
	exit();
}
}
?>
<div class="block_context" id="modify_block" align="center">
<p style="color:red">Form for modifying admin password</p>
				<form action="modifyPwd.php" method="post">
					<table>
						<tr>
							<th class="t1" >
							</th>
							<th class="t2">
							</th>	
						</tr>						
						<tr>
							<td style="text-align:right;">
							<b>Old Password:</b>
							</td>
							<td style="padding-left:16px;text-align:left;"><input type="password"  name="password0"  value=""/></td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>New Password:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<input type="password"  name="password1"  value=""/>		
						</td>
						</tr>
						<tr>
						<td style="text-align: right;">
							<b>Confirm:</b>
						</td>
						<td style="padding-left:16px;text-align: left;">
						<input type="password"  name="password2"  value=""/>		
						</td>
						</tr>
						</table>
						<p><input type="submit" value="Modify" />
						</p>
				</form>
			</div>
<?php 
include_once 'common/AdminTail.php';
?>